package
{
	import com.adobe.serialization.json.JSON;
	
	import org.egame.net.JSONPackage;
	
	import ui.ListItem;

	/**
	 * 存储列表
	 */ 
	public class StorageList
	{
		private var _arrItems:Array = new Array();
		
		/**
		 * 设置列表项列表
		 */ 
		public	function	setItemList( arr:Array):void{
			this._arrItems = arr;
		}
		
		/**
		 * 返回列表
		 */ 
		public	function	getItemList():Array{
			return this._arrItems;
		}
		
		/**
		 * 序列化
		 */ 
		public	function	toString():String{
			var pack:JSONPackage = new JSONPackage(0);
			pack.putInt("count", this._arrItems.length);
			for(var i:int = 0; i < this._arrItems.length; i++){
				var item:ListItem = this._arrItems[i] as ListItem;
				pack.putString("item"+i,item.toString()); 
			}
			return pack.toString();
		}
		
		/**
		 * 反序列化
		 */ 
		public	function	fromString(str:String):void{
			var obj:Object = JSON.decode(str);
			var pack:JSONPackage = new JSONPackage(0);
			pack.setInnerObj(obj);
			var count:int = pack.getInt("count");
			for(var i:int = 0; i < count; i++){
				var strItem:String = pack.getString("item"+i);
				var item:ListItem = new ListItem();
				item.fromString(strItem);
				this._arrItems.push(item);
			}
		}
	}
}